
//
//  DataHomeViewController.m
//  LianJiaData
//
//  Created by calow on 2018/9/26.
//  Copyright © 2018年 calow. All rights reserved.
//

#import "DataHomeViewController.h"
#import "NetWorkingWithAPI.h"
#import "DataModels.h"


@interface DataHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,assign)NSInteger page;
@property (nonatomic,strong)NSMutableArray * dataArray;
@property (nonatomic,assign)NSInteger startNumber;
@property (nonatomic,assign)NSInteger endNumber;


@property(nonatomic,strong)NSMutableArray * yhtArray;
@property(nonatomic,strong)NSMutableArray * glArray;
@property(nonatomic,strong)NSMutableArray * jyArray;
@property(nonatomic,strong)NSMutableArray * lhArray;
@property(nonatomic,strong)NSMutableArray * xwArray;


@end

@implementation DataHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.startNumber = 1;
    self.endNumber = 500;
    
    self.yhtArray = [NSMutableArray array];
    self.glArray = [NSMutableArray array];
    self.jyArray = [NSMutableArray array];
    self.lhArray = [NSMutableArray array];
    self.xwArray = [NSMutableArray array];

    self.dataArray = [NSMutableArray array];
    [self createArray];
}
-(void)createArray
{
    [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"100s"];
    for (NSInteger i =1; i<30000; i++)
    {
        [NetWorkingWithAPI getLianjiaData:[NSString stringWithFormat:@"https://nj.lianjia.com/api/newhouserecommend?type=1&query=https://nj.lianjia.com/ershoufang/pg%ld",i]  block:^(NSMutableDictionary *dictionary, NSString *error, NSString *networkingError) {
//            LJBaseClass * bc = [[LJBaseClass alloc]initWithDictionary:dictionary];
//            if (bc.data.count <1)
//            {
//                NSLog(@"数据已全部加载完毕");
//                [self reloadata];
//                return ;
//            }
            self.dataArray = (NSMutableArray *)[self.dataArray arrayByAddingObjectsFromArray:[dictionary objectForKey:@"data"]];
            
            
            
            self.startNumber++;
            self.endNumber ++;
        }];
    }
    [self  afterTime];

}
-(void)afterTime
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.startNumber == 1+1000)
        {
            [self reloadata];
     
        }else{
            [self afterTime];

            }
            
    });
}
-(void)reloadata
{
//    for (LJData * data in self.dataArray)
//    {
//        if ([data.districtName isEqualToString:@"雨花台"]) {
//            [self.yhtArray addObject:data];
//        }
//        if ([data.districtName isEqualToString:@"鼓楼"]) {
//            [self.glArray addObject:data];
//        }
//        if ([data.districtName isEqualToString:@"建业"]) {
//            [self.jyArray addObject:data];
//        }
//        if ([data.districtName isEqualToString:@"六合"]) {
//            [self.lhArray addObject:data];
//        }
//        if ([data.districtName isEqualToString:@"玄武"]) {
//            [self.xwArray addObject:data];
//        }
//    }
    
    [self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    if (indexPath.row == 0)
    {
        cell.textLabel.text = [NSString stringWithFormat:@"随机抽样数据总量:%ld",self.dataArray.count];

    }else if(indexPath.row ==1){
        cell.textLabel.text = [NSString stringWithFormat:@"雨花台:%ld",self.yhtArray.count];

    }else{
        cell.textLabel.text = [NSString stringWithFormat:@"鼓楼:%ld",self.glArray.count];
        
    }
    
    return cell;
}
@end
